Statistic = function() {
	return {
		initDataGrid : function() {
			
			$("#statDataGrid").datagrid({
				url				: '/pc/resource/statisticInfo.htm',
				fit				: true,
				fitColumns		: true,
				striped			: true,
				rownumbers		: true,
				autoRowHeight	: true,
				nowrap			: true,
				pagination		: true,
				singleSelect    : true,
				pageSize        : 20,
				pageList        : [10, 20, 30, 40, 50],
				method 			: 'POST',
				columns			: [[
				    { field : 'companyName',          title : '企业名称',     width : 100,   align : 'center' },
				    { field : 'departmentName',       title : '部门名称',     width : 100,   align : 'center' },
				    { field : 'employeeName',         title : '用户姓名',     width : 100,   align : 'center' },
				    { field : 'mobile',               title : '手机号码',     width : 100,   align : 'center' },
				    { field : 'todayCollection',      title : '今日采集',     width : 100,   align : 'center' },
				    { field : 'todayUpdate',          title : '今日更新',     width : 100,   align : 'center' },
				    { field : 'totalCollection',      title : '累计采集',     width : 100,   align : 'center' },
				    { field : 'totalUpdate',          title : '累计更新',     width : 100,   align : 'center' }
				]],
				toolbar       : '#toolBar'
			});
		},
		
		initCompany : function() {
			$("#company").combotree({
				url           : '/pc/company/companyTree.htm',
				editable      : false,
				panelHeight   : 200,
				onSelect      : function(node) {
					Statistic.initDepartment(node.id);
				}
			});
		},
		
		initDepartment : function(companyId) {
			$("#department").combotree({
				url           : '/pc/department/deptComTree.htm?companyId=' + companyId,
				editable      : false,
				panelHeight   : 200
			});
		},
		
		clearCondition : function() {
			Statistic.initCompany();
			Statistic.initDepartment("");
			$("#keyword").val("");
			$("#startTime").datebox('clear');
			$("#endTime").datebox('clear');
		},
		
		doSearch : function() {
			var companyId = $("#company").combotree("getValue");
			var departmentId = $("#department").combotree("getValue");
			var keyword = $.trim($("#keyword").val());
			var startTime = $("#startTime").datebox('getValue');
			var endTime = $("#endTime").datebox('getValue');
			if("" != startTime && "" != endTime) {
				if (startTime > endTime) {
					Ict.info('开始时间不能大于结束时间!');
					return;
				}
			}
			$('#statDataGrid').datagrid({
				queryParams   : {
					'companyId'    : companyId,
					'departmentId' : departmentId,
					'keyword'      : keyword,
					'startTime'    : startTime,
					'endTime'      : endTime
				},
				pageNumber    : 1,
				toolbar       : '#toolBar'
			});
		},
		
		init : function() {
			Statistic.initDataGrid();
			Statistic.initCompany();
			Statistic.initDepartment(0);
		}
	};
}();

$(function(){
	Statistic.init();
});